
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>registry管理 · docker swarm实践文档</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="Carey">
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-emphasize/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-alerts/style.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-code/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search-plus/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    
    <link rel="prev" href="compose_file.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    
    
        
        <li>
            <a href="http://carey.akhack.com" target="_blank" class="custom-link">Home</a>
        </li>
    
    

    
    <li class="divider"></li>
    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" >
            
                <span>
            
                    
                    基础环境
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="环境介绍.html">
            
                <a href="环境介绍.html">
            
                    
                    环境介绍
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="环境准备.html">
            
                <a href="环境准备.html">
            
                    
                    基础准备
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="安装docker.html">
            
                <a href="安装docker.html">
            
                    
                    安装 docker
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="compose_file.html">
            
                <a href="compose_file.html">
            
                    
                    compose file文档
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.2.5" data-path="registry仓库管理.html">
            
                <a href="registry仓库管理.html">
            
                    
                    registry管理
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" >
            
                <span>
            
                    
                    swarm 群集
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../swarm_book/创建群集.html">
            
                <a href="../swarm_book/创建群集.html">
            
                    
                    创建群集
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../swarm_book/portainer.html">
            
                <a href="../swarm_book/portainer.html">
            
                    
                    swarm管理工具Portainer
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../swarm_book/群集监控.html">
            
                <a href="../swarm_book/群集监控.html">
            
                    
                    cAdvisor InfluxDB Grafana搭建监控平台
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="../swarm_book/telegraf.html">
            
                <a href="../swarm_book/telegraf.html">
            
                    
                    Telegraf监控容器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="../swarm_book/Chronograf.html">
            
                <a href="../swarm_book/Chronograf.html">
            
                    
                    Chronograf显示监控数据
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" >
            
                <span>
            
                    
                    swarm service
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../service_book/nginx.html">
            
                <a href="../service_book/nginx.html">
            
                    
                    部署nginx服务
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" >
            
                <span>
            
                    
                    swarm stack
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../swarm_stack/lnmpwordpress.html">
            
                <a href="../swarm_stack/lnmpwordpress.html">
            
                    
                    部署wordpress
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../swarm_stack/build_eureka.md">
            
                <span>
            
                    
                    部署eureka
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >registry管理</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div class="search-plus" id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h2 id="registry&#x4ED3;&#x5E93;&#x7BA1;&#x7406;">registry&#x4ED3;&#x5E93;&#x7BA1;&#x7406;</h2>
<p><a href="https://docs.docker.com/registry/spec/api/" target="_blank">Docker Registry HTTP API V2</a></p>
<h3 id="&#x83B7;&#x53D6;&#x955C;&#x50CF;&#x5217;&#x8868;">&#x83B7;&#x53D6;&#x955C;&#x50CF;&#x5217;&#x8868;</h3>
<pre><code>$ curl http://10.0.20.112:5000/v2/_catalog
{&quot;repositories&quot;:[&quot;myflask&quot;,&quot;nginx&quot;]}
</code></pre><h3 id="&#x83B7;&#x53D6;&#x955C;&#x50CF;tags">&#x83B7;&#x53D6;&#x955C;&#x50CF;tags</h3>
<pre><code>$ curl http://10.0.20.112:5000/v2/nginx/tags/list
{&quot;name&quot;:&quot;nginx&quot;,&quot;tags&quot;:[&quot;1.15.7&quot;]}
</code></pre><h3 id="&#x83B7;&#x53D6;&#x955C;&#x50CF;etag">&#x83B7;&#x53D6;&#x955C;&#x50CF;Etag</h3>
<pre><code>$ curl --header &quot;Accept: application/vnd.docker.distribution.manifest.v2+json&quot; -I http://10.0.20.112:5000/v2/nginx/manifests/1.15.7
HTTP/1.1 200 OK
Content-Length: 948
Content-Type: application/vnd.docker.distribution.manifest.v2+json
Docker-Content-Digest: sha256:87e9b6904b4286b8d41bba4461c0b736835fcc218f7ecbe5544b53fdd467189f
Docker-Distribution-Api-Version: registry/2.0
Etag: &quot;sha256:87e9b6904b4286b8d41bba4461c0b736835fcc218f7ecbe5544b53fdd467189f&quot;
X-Content-Type-Options: nosniff
Date: Mon, 03 Dec 2018 04:44:48 GMT
</code></pre><h3 id="&#x5220;&#x9664;&#x955C;&#x50CF;">&#x5220;&#x9664;&#x955C;&#x50CF;</h3>
<pre><code>curl -X DELETE &apos;http://10.0.20.112:5000/v2/nginx/manifests/sha256:87e9b6904b4286b8d41bba4461c0b736835fcc218f7ecbe5544b53fdd467189f&apos;
[root@swarm1 register]# curl http://10.0.20.112:5000/v2/nginx/tags/list
{&quot;name&quot;:&quot;nginx&quot;,&quot;tags&quot;:null}
</code></pre><h3 id="&#x83B7;&#x53D6;&#x4ED3;&#x5E93;&#x6240;&#x6709;&#x955C;&#x50CF;&#x811A;&#x672C;">&#x83B7;&#x53D6;&#x4ED3;&#x5E93;&#x6240;&#x6709;&#x955C;&#x50CF;&#x811A;&#x672C;</h3>
<pre><code># coding:utf-8

import requests
import json

repo_ip = &apos;10.0.20.112&apos;
repo_port = 5000


def get_images_names(repo_ip, repo_port):
    docker_images = []
    url = &quot;http://&quot; + repo_ip + &quot;:&quot; + str(repo_port) + &quot;/v2/_catalog&quot;
    res = requests.get(url).content.strip()
    res_dic = json.loads(res)
    images_type = res_dic[&apos;repositories&apos;]
    for i in images_type:
        url2 = &quot;http://&quot; + repo_ip + &quot;:&quot; + str(repo_port) + &quot;/v2/&quot; + str(i) + &quot;/tags/list&quot;
        res2 = requests.get(url2).content.strip()
        res_dic2 = json.loads(res2)
        name = res_dic2[&apos;name&apos;]
        tags = res_dic2[&apos;tags&apos;]
        if not isinstance(tags, list):
            continue
        for tag in tags:
            docker_name = str(repo_ip) + &quot;:&quot; + str(repo_port) + &quot;/&quot; + name + &quot;:&quot; + tag
            docker_images.append(docker_name)
            print docker_name
    return docker_images


get_images_names(repo_ip, repo_port)
</code></pre><h3 id="&#x5220;&#x9664;&#x4ED3;&#x5E93;&#x955C;&#x50CF;&#x811A;&#x672C;">&#x5220;&#x9664;&#x4ED3;&#x5E93;&#x955C;&#x50CF;&#x811A;&#x672C;</h3>
<pre><code># coding:utf-8
import requests
import sys
import json

host = &apos;10.0.20.112&apos;
port = 5000

if len(sys.argv) &lt; 2:
    print(&quot;&#x53C2;&#x6570;&#x9519;&#x8BEF;: None&quot;)
    sys.exit(1)


def get_images_names(repo_ip, repo_port):
    docker_images = []
    url = &quot;http://&quot; + repo_ip + &quot;:&quot; + str(repo_port) + &quot;/v2/_catalog&quot;
    res = requests.get(url).content.strip()
    res_dic = json.loads(res)
    images_type = res_dic[&apos;repositories&apos;]
    for i in images_type:
        url2 = &quot;http://&quot; + repo_ip + &quot;:&quot; + str(repo_port) + &quot;/v2/&quot; + str(i) + &quot;/tags/list&quot;
        res2 = requests.get(url2).content.strip()
        res_dic2 = json.loads(res2)
        name = res_dic2[&apos;name&apos;]
        tags = res_dic2[&apos;tags&apos;]
        if not isinstance(tags, list):
            continue
        for tag in tags:
            docker_name = str(repo_ip) + &quot;:&quot; + str(repo_port) + &quot;/&quot; + name + &quot;:&quot; + tag
            docker_images.append(docker_name)
            # print docker_name
    return docker_images


images_list = get_images_names(repo_ip=host, repo_port=port)
delete_images_list = sys.argv[1:]

for image in delete_images_list:
    if image not in images_list:
        print(&quot;{}: image not found&quot;.format(image))
        continue

    imgs = image.split(&apos;/&apos;)[-1]
    img, ver = imgs.split(&apos;:&apos;)[0], imgs.split(&apos;:&apos;)[1]
    headers = {
        &quot;Accept&quot;: &quot;application/vnd.docker.distribution.manifest.v2+json&quot;
    }
    etag_url = &quot;http://{}:{}/v2/{}/manifests/{}&quot;.format(host, port, img, ver)
    ret = requests.get(url=etag_url, headers=headers)
    if ret.status_code != requests.codes.ok:
        print(&quot;{}:{} &#x5220;&#x9664;&#x5931;&#x8D25;&quot;.format(img, ver))
        continue

    etag = ret.headers.get(&quot;Etag&quot;).replace(&quot;\&quot;&quot;, &quot;&quot;)
    delete_images_url = &quot;http://{}:{}/v2/{}/manifests/{}&quot;.format(host, port, img, etag)
    del_ret = requests.delete(url=delete_images_url)
    if del_ret.ok:
        print(&quot;{}:{} &#x5220;&#x9664;&#x6210;&#x529F;&quot;.format(img, ver))
    else:
        print(&quot;{}:{} &#x5220;&#x9664;&#x5931;&#x8D25;&quot;.format(img, ver))
</code></pre>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="compose_file.html" class="navigation navigation-prev navigation-unique" aria-label="Previous page: compose file文档">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"registry管理","level":"1.2.5","depth":2,"next":{"title":"swarm 群集","level":"1.3","depth":1,"ref":"","articles":[{"title":"创建群集","level":"1.3.1","depth":2,"path":"swarm_book/创建群集.md","ref":"swarm_book/创建群集.md","articles":[]},{"title":"swarm管理工具Portainer","level":"1.3.2","depth":2,"path":"swarm_book/portainer.md","ref":"swarm_book/portainer.md","articles":[]},{"title":"cAdvisor InfluxDB Grafana搭建监控平台","level":"1.3.3","depth":2,"path":"swarm_book/群集监控.md","ref":"swarm_book/群集监控.md","articles":[]},{"title":"Telegraf监控容器","level":"1.3.4","depth":2,"path":"swarm_book/telegraf.md","ref":"swarm_book/telegraf.md","articles":[]},{"title":"Chronograf显示监控数据","level":"1.3.5","depth":2,"path":"swarm_book/Chronograf.md","ref":"swarm_book/Chronograf.md","articles":[]}]},"previous":{"title":"compose file文档","level":"1.2.4","depth":2,"path":"base_book/compose_file.md","ref":"base_book/compose_file.md","articles":[]},"dir":"ltr"},"config":{"plugins":["emphasize","alerts","code","-lunr","-search","search-plus","splitter"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"emphasize":{},"splitter":{},"code":{"copyButtons":true},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"alerts":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"search-plus":{}},"theme":"default","author":"Carey","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"docker swarm实践文档","language":"zh-hans","links":{"sidebar":{"Home":"http://carey.akhack.com"}},"gitbook":"*"},"file":{"path":"base_book/registry仓库管理.md","mtime":"2018-12-04T03:22:50.876Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2018-12-04T03:25:36.834Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-alerts/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-code/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-plus/jquery.mark.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-plus/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

